package com.yunc.modules.sys.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunc.base.controller.CommonController;
import com.yunc.common.utils.R;
import com.yunc.modules.sys.entity.SysJobLog;
import com.yunc.modules.sys.service.ISysJobLogService;
import org.apache.commons.lang.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 定时任务日志
 *
 * @author congcong tao
 * @create 2018/11/21 下午8:08
 */
@RestController
@RequestMapping("sysJobLog")
public class SysJobLogController extends CommonController {

    private static final Logger logger = LogManager.getLogger(SysJobLogController.class);

    @Autowired
    private ISysJobLogService sysJobLogService;
    
    @GetMapping("/page")
    public R page(Page<SysJobLog> page, SysJobLog sysJobLog){
        QueryWrapper<SysJobLog> ew = new QueryWrapper<>();
        ew.orderByDesc("create_time");
        sysJobLogService.page(page, ew);
        return R.ok().put("data", page.getRecords()).put("count", page.getTotal());
    }

    @DeleteMapping("/delete/{ids}")
    // @RequiresPermissions("sys:joblog:delete")
    public R info(@PathVariable String ids){
        if (StringUtils.isNotEmpty(ids)) {
            String[] idArr = ids.split(",");
            boolean flag = sysJobLogService.removeByIds(Arrays.asList(idArr));
            if (flag) {
                return R.ok("删除成功");
            }
        }
        return R.error("删除失败");
    }

}
